<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="props.formOperate!=='view'?['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']:[]"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xCarinfo.quick Search Fields') })"
        >
            <FileUpload v-if="props.formOperate!=='view'" action="XCarinfo/importData" name="挂车导入" :data="{corp:props.companyName}" />
            <FileUpload v-if="props.formOperate!=='view'" action="XCarinfo/importData" name="牵引头导入" :data="{corp:props.companyName}"/>
        </TableHeader>


        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { xCarinfo } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import FileUpload from '/@/components/fileUpload/index.vue'

const { t } = useI18n()
const props = defineProps({
    companyName:String,
    formOperate:String
})
const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(xCarinfo),
    {
        pk: 'ID',
        column: [
            { type: 'selection', align: 'center', operator: false },

            { label: t('xCarinfo.CORP'), prop: 'CORP', align: 'center' },
            { label: t('xCarinfo.TRUCKNO'), prop: 'TRUCKNO', align: 'center' },
            { label: t('xCarinfo.GPS'), prop: 'GPS', align: 'center' },
            { label: t('xCarinfo.POLICYTYPE'), prop: 'POLICYTYPE', align: 'center' },
            { label: t('xCarinfo.POLICYNO'), prop: 'POLICYNO', align: 'center' },
            { label: t('xCarinfo.POLICYDATE'), prop: 'POLICYDATE', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
           { label: t('xCarinfo.OP'), prop: 'OP', align: 'center' },
            { label: t('xCarinfo.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false ,show:props.formOperate!=='view'},
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'CORP', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)

provide('baTable', baTable)


const route = useRoute()
const type = route.path === '/admin/corplib/customer'? 1:route.path === '/admin/corplib/supplier'||route.path === '/admin/corplib/supplier/approve'?2:null

onMounted(() => {
    baTable.table.ref = tableRef.value
    if(type){
        baTable.table.filter!.type = type
        baTable.table.filter!.CORP = props.companyName
    }
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
export default defineComponent({
    name: 'xCarinfo',
})
</script>

<style scoped lang="scss"></style>
